//
//  RegistViewController.m
//  Tongcheng
//
//  Created by 邢广范 on 2017/4/3.
//  Copyright © 2017年 Tongcheng. All rights reserved.
//注册界面（填写昵称和年龄）

#import "RegistViewController.h"
#import "RegistOperator.h"
#import "RegistModel.h"
#import "RegistDataModel.h"
#import "RegistInfoViewController.h"
#import "AppDelegate.h"
#import "CheckUtils.h"

@interface RegistViewController ()

@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
- (IBAction)nextBtnClick:(id)sender;

@property (nonatomic, copy) NSString *sexType;

@end

@implementation RegistViewController

- (void)setupNavigation
{
    self.navigationItem.title = @"用户注册";
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavigation];
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)nextBtnClick:(id)sender {
    NSString *name = [CheckUtils checkUserName:self.userNameTextField.text];
    if (name) {
        [self showToastMessage:name];
    }else{
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        dic[@"user_login"] = self.userNameTextField.text;
        dic[@"user_pass"] = self.passwordTextField.text;
        dic[@"sex"] = @"0";
        RegistOperator *operator = [[RegistOperator alloc] initWithParams:dic];
        [self.networkingManager asyncTaskOnVC:self operator:operator successBlock:^(BaseModel *baseModel) {
            if ([baseModel.code isEqualToString:@"1"]) {
                [self showToastMessage:baseModel.msg];
                self.config.userId = operator.data.data.user_id;
                self.config.token = operator.data.data.token;
                self.config.userName = self.userNameTextField.text;
                AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
                [delegate choosViewController];
            }else{
                [self showToastMessage:baseModel.msg];
            }
        } failBlock:^(BaseModel *baseModel) {
            
        }];
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
